<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">


        // for  in 遍历数组
        var arr = [1, 2, 3, 4, 5];
        console.log(arr['1']);

        for(var prop in arr){
            console.log(prop, typeof(prop));
            console.log(arr[prop]);
        }


        //对象的深度拷贝
        function deepClone(origin, target) {
            target = target || {};
            var toStr = Object.prototype.toString,
                arrStr = '[object Array]'; 
            for (var prop in origin) { //遍历对象
                if (origin.hasOwnProperty(prop)) {
                    if (origin[prop] !== null && typeof(origin[prop]) == 'object') {
                    // 判断是不是原始值
                        if (toStr.call(origin[prop]) == arrStr) {
                        // 判断是数组还是对象
                            target[prop] = [];
                        } else {
                            target[prop] = {};// 建立空的对象或者数组
                        }

                       // target[prop] = toStr.call(origin[prop]) == arrStr ? [] : {};
                        deepClone(origin[prop], target[prop]);
                        // 递归拷贝
                    } else {
                        target[prop] = origin[prop];
                    }
                }
            } 
            return target;
        }

        var obj = {
            name: 'abc',
            age: 123,
            sex: 'female',
            card: [1, 2] 
        }

        var obj1 = {};

        deepClone(obj, obj1);  
        obj.card.push(1);  
    </script>
</body>
</html>